<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('会议室设置') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('名称')" prop="name">
        <el-input
          v-model="queryParams.name"
          size="small"
          :placeholder="$t('名称')"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('地点')" prop="place">
        <el-input
          v-model="queryParams.place"
          size="small"
          :placeholder="$t('地点')"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">{{ $t("搜索") }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t("重置") }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['oa:meetingroom:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >{{ $t("新增") }}</el-button>
      </el-col>
    </el-row>

    <el-table
      v-loading="loading"
      :data="oaMeetingRoomList"
      tooltip-effect="darkTable"
      border
      @selection-change="handleSelectionChange"
    >
      <el-table-column :label="$t('名称')" align="center" prop="name" show-overflow-tooltip />
      <el-table-column
        :label="$t('地点')"
        align="center"
        prop="place"
        show-overflow-tooltip
        width="120"
      />
      <el-table-column :label="$t('电话')" align="center" prop="phone" show-overflow-tooltip width="120" />
      <el-table-column :label="$t('最大容纳人数')" align="center" prop="largestNumber" show-overflow-tooltip width="120" />
      <el-table-column
        :label="$t('是否有电话会议')"
        align="center"
        prop="callMeeting"
        :formatter="callMeetingFormat"
        show-overflow-tooltip
        width="120"
      />
      <el-table-column
        :label="$t('是否有视频会议')"
        align="center"
        prop="videoMeeting"
        :formatter="videoMeetingFormat"
        show-overflow-tooltip
        width="120"
      />
      <el-table-column :label="$t('操作')" align="center" fixed="right" width="150" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['oa:meetingroom:edit']"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-hasPermi="['oa:meetingroom:remove']"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改会议室对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" width="50%" :close-on-click-modal="false" :lock-scroll="false">
      <oaMeetingRoomForm ref="oaMeetingRoomForm" />
    </el-dialog>
  </div>
</template>

<script>
import {
  listOaMeetingRoom,
  delOaMeetingRoom,
  saveOaMeetingRoom
  // updateOaMeetingRoom,
} from '@/api/oa/meeting/oaMeetingRoom'
import oaMeetingRoomForm from './oaMeetingRoomForm.vue'
export default {
  components: {
    oaMeetingRoomForm
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 会议室表格数据
      oaMeetingRoomList: [],
      // 弹出层标题
      title: '会议室',
      // 是否显示弹出层
      formOpen: false,
      // 是否有电话会议字典
      callMeetingOptions: [],
      // 是否有视频会议字典
      videoMeetingOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        place: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      oaMeetingRoomData: ''
    }
  },
  created() {
    this.getList()
    this.getDicts('sys_yes_no').then(response => {
      this.callMeetingOptions = response.data
    })
    this.getDicts('sys_yes_no').then(response => {
      this.videoMeetingOptions = response.data
    })
  },
  mounted() {
    this.$bus.$on('toggle', () => {
      this.handleAdd()
    })
  },
  methods: {
    /** 查询会议室列表 */
    getList() {
      this.loading = true
      listOaMeetingRoom(this.queryParams).then(response => {
        this.oaMeetingRoomList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 是否有电话会议字典翻译
    callMeetingFormat(row) {
      return this.selectDictLabel(this.callMeetingOptions, row.callMeeting)
    },
    // 是否有视频会议字典翻译
    videoMeetingFormat(row) {
      return this.selectDictLabel(this.videoMeetingOptions, row.videoMeeting)
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        name: undefined,
        place: undefined,
        phone: undefined,
        largestNumber: undefined,
        callMeeting: undefined,
        videoMeeting: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    },
    // 取消按钮
    cancel() {
      this.formOpen = false
      this.reset()
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.oaMeetingRoomForm.init(null)
      })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.formOpen = true
      this.$nextTick(() => {
        this.$refs.oaMeetingRoomForm.init(row)
      })
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          saveOaMeetingRoom(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess(this.$t('修改成功'))
              this.open = false
              this.getList()
            } else {
              this.msgError(response.msg)
            }
          })
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
        confirmButtonText: this.$t('确定'),
        cancelButtonText: this.$t('取消'),
        type: 'warning'
      })
        .then(function() {
          return delOaMeetingRoom(ids)
        })
        .then(() => {
          this.getList()
          this.msgSuccess(this.$t('删除成功'))
        })
        .catch(function() {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.downLoadExcel('/meeting/oaMeetingRoom/export', this.queryParams)
    }
  }
}
</script>
